package org.jeecg.modules.enhance;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.arc.entity.BaseWaterPrices;
import org.jeecg.modules.arc.service.impl.BaseWaterPricesServiceImpl;
import org.jeecg.modules.online.cgform.enhance.CgformEnhanceJavaInter;
import org.jeecg.modules.online.config.exception.BusinessException;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component("waterPriceEnhance")
public class WaterPriceEnhance implements CgformEnhanceJavaInter {

    @Override
    public int execute(String table, Map<String, Object> map) throws BusinessException {
        return 0;
    }

    @Override
    public int execute(String table, JSONObject jsonObject) throws BusinessException {

        BaseWaterPricesServiceImpl impl = (BaseWaterPricesServiceImpl) SpringContextUtils.getBean("baseWaterPricesServiceImpl");

        int count = impl.count(new LambdaQueryWrapper<BaseWaterPrices>()
                .eq(BaseWaterPrices::getNatureId, jsonObject.getString("nature_id"))
                .eq(BaseWaterPrices::getTierNo, jsonObject.getString("tier_no")));
        if(count>0){
          throw new BusinessException("该用水性质已存在");
        }
        return 0;
    }
}
